﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;

namespace FBPChaos
{
    static class InputHelper
    {
        private const Keys menuKey = Keys.M;
        private const string letters = "abcdefghijklmnopqrstuvwxyz";
        private const Keys selectKey = Keys.S;

        public static int GetNumberKey(Keys[] keys)
        {
            if (keys.Length > 0)
            {
                if (keys[0] >= Keys.D0 && keys[0] <= Keys.D9)
                {
                    string key;
                    key = keys[0].ToString().Substring(1, 1);
                    return int.Parse(key);
                }
            }
            return -1;
        }

        public static bool SelectKeyPressed(Keys[] keys)
        {
            if (keys.Length > 0)
            {
                if (keys[0] == selectKey)
                    return true;
            }
            return false;
        }

        public static bool EnterKeyPressed(Keys[] keys)
        {
            if (keys.Length > 0)
            {
                if (keys[0] == Keys.Enter)
                    return true;
            }
            return false;
        }

        public static bool KeyPressed(Keys[] keys)
        {
            if (keys.Length > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static bool menuKeyPressed(Keys[] keys)
        {
            if(keys.Length >0)
            {
                if (keys[0] == menuKey)
                    return true;
            }
            return false;
        }

        public static bool spellKeyPressed(Keys[] keys, int numberOfSpells)
        {
            if (keys[0] <= (Keys.A + numberOfSpells))
            {
                return true;
            }
            return false;

        }

        public static char numberToLetter(int number)
        {
            return letters.ToUpper().ToCharArray(number, 1)[0];
        }

        public static int letterToNumber(char letter)
        {
            return letters.IndexOf(letter);
        }

        public static bool cursorKeyPressed(Keys[] keys)
        {
            if (keys[0] == Keys.Up || keys[0] == Keys.Down || keys[0] == Keys.Right || keys[0] == Keys.Left)
            {
                return true;
            }
            return false;
        }

        public static Direction cursorKey(Keys[] keys)
        {
            if (keys[0] == Keys.Up)
                return Direction.Up;
            else if (keys[0] == Keys.Down)
                return Direction.Down;
            else if (keys[0] == Keys.Left)
                return Direction.Left;
            else if (keys[0] == Keys.Right)
                return Direction.Right;
            else if (keys[0] == selectKey)
                return Direction.Select;
            else
                return Direction.None;
        }
    }
}
